package com.meme.editor.model.sprite2d;

import java.util.ListIterator;

import com.meme.editor.PropertyValueModification;
import com.meme.editor.PropertyValueModificationList;
import com.meme.editor.property.PropertyFactory;

public class ModuleSequence extends ModulePart
{
	
	public static final String PropertyName_Duration = "Duration";
	
	ModulePart mModuleInstance;
	int            mDuration;	

	public ModuleSequence (Module module, int offX, int offY, int flags, int palID, int duration)
	{
		super (module, offX, offY, flags, palID);
		
		createPublicProperty (GroupName_ModulePartGroup, PropertyName_Duration, PropertyFactory.ValueType_Number );

		
		setDuration (duration);
	}
	
	public ModuleSequence (Module module, int offX, int offY)
	{
		this (module, offX, offY, 0, 0, 1);
	}	
	
	public ModuleSequence (Module module)
	{
		this (module, 0, 0, 0, 0, 1);
	}
	
	public ModuleSequence ()
	{
		this (null);
	}
	
	@Override
	public String getDefaultName ()
	{
		return "Frame";
	}
	
	@Override
	protected void _handleModifyingPropertyValues (PropertyValueModificationList modications)
	{		
		ListIterator<PropertyValueModification> iter = modications.listIterator();
		while ( iter.hasNext() )
		{
			PropertyValueModification mod = iter.next();
			
			if (   mod.mGroupName.equals (GroupName_ModulePartGroup) )
			{
				if ( mod.mPropertyName.equals (PropertyName_Duration) )
				{
					setDuration (( (Float) (mod.mNewValue) ).intValue());
					iter.remove();
				}
			}
		}
			
		super._handleModifyingPropertyValues (modications);
	}
	
	public void setDuration (int duration)
	{
		if ( duration <= 0 )
			duration = 1;
		
		mDuration = duration;
		
		changePublicPropertyValue ( GroupName_ModulePartGroup, PropertyName_Duration, new Float (mDuration) );
	}
	
	public int getDuration ()
	{
		return mDuration;
	}
}
